package com.aaa.tmr.controller;

import com.aaa.tmr.entity.PotentialCustomer;
import com.aaa.tmr.service.PotentialCustomerService;
import com.aaa.tmr.util.Result;
import com.aaa.tmr.util.ReturnStatus;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;

/**
 * (PotentialCustomer)表控制层
 *
 * @author makejava
 * @since 2021-03-24 16:24:16
 */
@Controller
@RequestMapping("potentialCustomer")
public class PotentialCustomerController {
    /**
     * 服务对象
     */
    @Resource
    private PotentialCustomerService potentialCustomerService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ResponseBody
    @RequestMapping("selectOne")
    public Result selectOne(Integer id) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0L,
                this.potentialCustomerService.queryById(id));
    }

    /**
     * 跳转部门分页列表页面
     *
     * @return
     */
    @RequestMapping("toPage")
    public String toPage() {
        return "back/potentialCustomer-page";
    }

    /**
     * 通过实体作为筛选条件查询
     *
     * @return 对象列表
     */
    @ResponseBody
    @RequestMapping("queryAll")
    public Result queryAll(Integer page, Integer limit, PotentialCustomer potentialCustomer) {
        PageInfo pageInfo = potentialCustomerService.queryAll(page, limit, potentialCustomer);
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(),
                pageInfo.getTotal(), pageInfo.getList());
    }

    /**
     * 新增数据
     *
     * @param potentialCustomer 实例对象
     * @return 实例对象
     */
    @ResponseBody
    @RequestMapping("insert")
    public Result insert(PotentialCustomer potentialCustomer) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0L,
                this.potentialCustomerService.insert(potentialCustomer));
    }

    /**
     * 修改数据
     *
     * @param potentialCustomer 实例对象
     * @return 实例对象
     */
    @ResponseBody
    @RequestMapping("update")
    public Result update(PotentialCustomer potentialCustomer) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0L,
                this.potentialCustomerService.update(potentialCustomer));
    }

    /**
     * 通过主键删除数据
     *
     * @param potentialCustomerId 主键
     * @return 是否成功
     */
    @ResponseBody
    @RequestMapping("deleteById")
    public Result deleteById(Integer potentialCustomerId) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0L,
                this.potentialCustomerService.deleteById(potentialCustomerId));
    }
}
